export async function* insertionSort(array, compare, swap, set) {
    const n = array.length;
    
    for (let i = 1; i < n; i++) {
        let j = i;
        
        while (j > 0) {
            yield { type: 'compare', indices: [j - 1, j] };
            
            if (await compare(j, j - 1)) {
                yield { type: 'swap', indices: [j - 1, j] };
                await swap(j - 1, j);
                j--;
            } else {
                break;
            }
        }
    }
    
    yield { type: 'complete' };
}